<?php
	
	class PDataManager
	{
		var $puzzle;
		
		var $containers;
		var $default_container;
		
		
		function PDataManager(&$owner)
		{
			$this->puzzle = $owner;
			$this->containers = array();
		}
		
		function addContainer(&$container)
		{
			$this->containers[] = $container;
			
			if ($default_container == null)
			{
				$this->default_container = &$container;
			}
		}
		
		function existModel($model, $extension)
		{
			$DS = $this->puzzle->config['DS'];
			
			if ($extension == null)
			{
				$extension = $this->puzzle->PEM->default_extension;
			}
			
			if ($this->puzzle->PEM->existExtension($extension))
			{
	
				if (file_exists($this->puzzle->config['dir_ext'] . $DS . $extension . $DS .  $this->puzzle->config['dir_ext_src'] . $DS . $this->puzzle->config['dir_ext_models'] . $DS . $model))
				{
					return true;
				}
				else
				{
					return false;
				}
			}
			else
			{
				return false;
			}
		}
		
		function createModel($model, $extension = null)
		{
			if ($extension == null)
			{
				$extension = $this->puzzle->PEM->current_extension;
			}
			
			if ($this->puzzle->PEM->existExtension($extension))
			{
				if ($this->existModel($model, $extension))
				{
					$m = new PModel($this->puzzle, $extension, $model);
					return $m;
				}
				else
				{
					die("Puzzle :: Error :: Model $model in extension $extension does not exist");
				}
			}
			else
			{
				die("Puzzle :: Error :: Loading model $model :: Extension $extension does not exist");
			}
		}
	}
	
?>
